home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 015a / do1003.zip / CALC.SCR < prev    next >
Text File  |  1991-12-16  |  3KB  |  108 lines

  1. *┌────────────────────────────────────────────────────────────────┐
  2. *│SCRIPT: CALC.SCR - A calculator simulation                      │
  3. *│                   Simulates a calculator. Returns answer in    │
  4. *│                   %RESULT which is available to other scripts  │
  5. *└────────────────────────────────────────────────────────────────┘
  6. .clr
  7. * Make sure the RESULT variable is not defined.  Result might be left over
  8. * from another script.
  9. /CLEAR Result
  10. * Initialize the tape row
  11. /MATH Row 0
  12. * Display the calculator screen
  13. :DispCalculator
  14. .re
  15.  
  16. /BIG DO 4
  17. .wh
  18.     C A L C U L A T O R
  19.  
  20. .wi 3 19 38 22
  21. Enter "C" to  Clear
  22. Enter "H" for Help
  23. Enter "Q" to  Quit
  24. .wi full
  25. /MATH Row 0
  26. /FRAME ~179 ~196 ~217 ~191 ~192 ~218
  27. /box 1 23 80 25 7 7 ""
  28. /box 40 1 80 22 7 7 " Tape "
  29. /box 1 18 39 22 7 7 ""
  30. /FRAME RESET
  31. * Initialize the formula if <enter> pressed
  32. /SET Default ""
  33. * Start of the calculator loop
  34. :TOP
  35. .go 3 24
  36. * Get the formula and evaluate it
  37. /GETS Calc default "" 60 UC
  38. /IF %calc NE Q END
  39. /IF %calc NE H HELP
  40. /IF %calc EQ C docalc
  41. /CLEAR Result
  42. /SET Default ""
  43. /MATH Row 0
  44. .wi 42 2 79 21 clr wi full
  45. /GOTO TOP
  46. :docalc
  47. * if this is a continuation calculation, append RESULT to it.
  48. /IF %calc LK "[^,+,/,*,-]*" Start
  49. /IF %Result NE "" Clip
  50. /MATH Result %Result%calc
  51. /GOTO show
  52. :Clip
  53. /SET Calc @trim(%calc," +-/*",L)
  54. :start
  55. /MATH Result %calc
  56. :show
  57. * show the result.  Printing at the bottom of the window (row 20)
  58. * will scroll the window
  59. /inc row
  60. /if %row GT 20 ShowResult
  61. /MATH row 20
  62. :showresult
  63. .wi 42 2 79 21 go 1 %row
  64. %Result
  65. .wi full
  66. * set the default to the last forumla and loop
  67. /SET Default %Calc
  68. /GOTO TOP
  69. :HELP
  70. .wi full clr
  71. /SET Title "DO Calculator Help"
  72.  
  73. »bo«%title(C80)»#«
  74. .wi 1 3 80 25
  75.     The DO Calculator can perform basic calculations using the
  76.     following operators and functions:
  77.  
  78.     »wh«+»#«         Addition               »wh«/»#«    Division
  79.     »wh«-»#«         Subtraction            »wh«^»#«    Exponentiation
  80.     »wh«*»#«         Multiplication         »wh«()»#«   Grouping
  81.     »wh«ABS»#«       Returns the absolute value of the argument
  82.     »wh«ATAN»#«      Returns the arctangent of the argument
  83.     »wh«COS»#«       Returns the cosine of the argument
  84.     »wh«EXP»#«       Returns the exponential
  85.     »wh«LN»#«        Returns the natural logarithm of the argument
  86.     »wh«ROUND»#«     Rounds a real number to an integer
  87.     »wh«SIN»#«       Returns the sine of the argument
  88.     »wh«SQRT»#«      Returns the square root of the argument
  89.     »wh«SQR»#«       Returns the square of the argument
  90.     »wh«TRUNC»#«     Truncates a real to an integer
  91. .pg -25 clr
  92.     Enter the formula of up to 60 characters and press <enter>.
  93.     The result is displayed on the "tape". If you wish to perform
  94.     a continuing calculation, start the formula with "+,-,/,*".
  95.  
  96.     Enter "C" to clear the tape and "Q" to quit.
  97.  
  98.     If a calculation was performed and not cleared, the result of
  99.     the final calculation is contained in the variable "RESULT".
  100. .pg -25 wi full clr
  101. /GOTO DispCalculator
  102. :END
  103. * clear the screen and remove all variables except RESULT
  104. .wi full clr
  105. /CLEAR CALC
  106. /CLEAR DEFAULT
  107. /CLEAR ROW
  108.